<?

class Qi_Profiler
{
	public $timers = array();

	public function __construct()
	{
	}

	public function start($label = null)
	{
		if (!$label) $label = $microtime;
		$this->timers[$label] = new Qi_Profiler_Timer();
	}

	public function stop($label = null)
	{
		$timer = $label ? $this->timers[$label] : end($this->timers);
		$timer->stop();
	}

	public function point($label = null)
	{
		$this->stop();
		$this->start($label);
	}

	public function test()
	{
		foreach($this->timers as $label => $t):
			echo "\n[$label]\n";
			print_r($t->avg->avg);
		endforeach;
	}
}

require_once "init.php";

header("Content-Type: text/plain");
$p = new Qi_Profiler;
$p->start("md5");
md5("neves");
$p->stop();

$p->start('require_once "db.php"');
require_once "db.php";
$p->stop();

$p->start("vazio");
$p->stop();

$p->test();
echo "\n\n".abs((microtime(true) - microtime(true))*1000000.0);
/*
//printf("%0.1fu %0.1fu %0.1fu", $p->min_microtime * 1000000, $p->var_creation_time * 1000000, $p->call_func_time * 1000000);
$numeros = array();
var_dump(1000000*$p->min);
for($i = 0; $i < 20; $i++):
	$start = microtime(true);
	$t = str_repeat("!", 100);
	$end = microtime(true);
	$delta = $end - $start;
	var_dump(1000000*$delta);
	$numeros[] = 1000000*$delta;
endfor;
$min = min($numeros);
$max = max($numeros);
echo "<pre>";
print_r($p);
$valores = Qi_Math::numeros($numeros);

foreach($numeros as &$n) $n = sprintf("%0.1f", $n);

$numeros = implode(",", $numeros);
echo $numeros."\n";
print_r($valores);
var_dump($min, $max);
$std = sprintf("%0.1f", $valores["stdv_avg"]);
$avg = sprintf("%0.1f", $valores["avg"]);

$min = sprintf("%0.1f", $valores["stdv_min"]);
$max = sprintf("%0.1f", $valores["stdv_max"]);

$url = "http://chart.apis.google.com/chart?chs=500x300&cht=lc&chd=t:$numeros|$std,$std|$avg,$avg&chds=$min,$max&chco=ff0000,00ff00,000000&chg=0,5";
*/
?>
<img src="<?=$url?>" />